import axios from "axios";

const isNewVersion = async () => {
  let url = `//${window.location.host}/version.json?t=${new Date().getTime()}`
  let res = await axios.get(url)
  if (res.status === 200) {
    let vueVersion = res.data.version;
    let localVueVersion = localStorage.getItem('vueVersion');

    /**
     * 判断当前代码版本是否与服务器中代码版本一致,如不一致则刷新页面获取最新
     * 1.判断是否有存储版本号
     * 2.判断旧版本号是否与新版本号一致
     */
    if (localStorage && localVueVersion != vueVersion) {
      localStorage.setItem('vueVersion', vueVersion)
      window.location.reload()
    } else {
      localStorage.setItem('vueVersion', vueVersion)
    }
  }
  return res.data.version;

}

export default {
  isNewVersion
}